package leetcode_1_200;

public class LeeCode_165 {
    public static void main(String[] args) {
        System.out.println(compareVersion("1.01", "9.7.5"));
    }
    private static int compareVersion(String version1, String version2) {
        String[] v1s = version1.split("\\.");
        String[] v2s = version2.split("\\.");
        int i = 0;
        while (i < v1s.length && i < v2s.length){
            int v1 = Integer.parseInt(v1s[i]);
            int v2 = Integer.parseInt(v2s[i]);
            if (v1 > v2)
                return 1;
            if (v1 < v2)
                return -1;
            i++;
        }
        while (i < v1s.length){
            if (Integer.parseInt(v1s[i]) > 0){
                return 1;
            }
            i++;
        }
        while (i < v2s.length){
            if (Integer.parseInt(v2s[i]) > 0){
                return -1;
            }
            i++;
        }
        return 0;
    }
}
